<%@ page contentType="text/html;charset=UTF-8"
	import="petertel.pbx.conf.*"%>
<%@ include file="common/common.jsp"%>
<c:set var="currentDevice" value="${sipConf.currentDevice}" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>sip配置</title>
<link href="${contextPath}/style/common.css" rel="stylesheet"
	type="text/css" />
<script src="${contextPath}/jscript/jquery-1.7.2.js"></script>
<script type="text/javascript">

$(document).ready(function(){
 });

	function insert(index){
		var propertyName = $("#insertNameSelect").val();
		location.href="${contextPath}/sipConf/insert.fb?deviceName=${currentDevice.name}&propertyName="+propertyName;
	}
	
	function reset() {
		location.href="${contextPath}/sipConf/reset.fb?deviceName=${currentDevice.name}";
	}
	
	function remove(index) {
		location.href="${contextPath}/sipConf/remove.fb?deviceName=${currentDevice.name}&index="+index;
	}
	
	function edit(index){
		location.href="${contextPath}/sipConf/edit.fb?deviceName=${currentDevice.name}&index="+index;
	}
	
	function addDevice() {
		var deviceName = prompt("请输入设备名：");
		location.href = "${contextPath}/sipConf/addDevice.fb?deviceName="+deviceName;
	}

	function deleteDevice() {
		location.href="${contextPath}/sipConf/removeDevice.fb?deviceName=${currentDevice.name}";
	}
	
	function apply() {
		location.href="${contextPath}/sipConf/apply.fb?deviceName=${currentDevice.name}";
	}
	
	function save(form){
		$.post("${contextPath}/sipConf/save.fb",$(form).serialize(),function(data){
		 },"json");		
	}
</script>
</head>
<body>
	<div id="tools" class="listbar">
		<div style="float: left;">
			<div style="float: left;" class="input-text">名称：</div>
			<input name="name" type="text" class="gray" />
		</div>
		<div style="float: left; margin-left: 5px;">
			<input type="button" value="重置" class="button-blue"
				onclick="reset();" />
		</div>
		<div style="float: left; margin-left: 5px;">
			<input type="button" id="applyButton" value="应用"
				class="${sipConf.applyButtonClass} " onclick="apply();" /> <input
				type="button" id="addButton" value="添加" class="button-blue"
				onclick="addDevice();" /> <input type="button" id="deleteButton"
				value="删除" class="button-blue" onclick="deleteDevice();" />
		</div>
	</div>
	<div style="margin-left: 10px;">
		<c:forEach items="${sipConf.children}" var="device" varStatus="vs">
			<a href="${contextPath}/sipConf/show.fb?deviceName=${device.name}"
				class="${device==currentDevice?'blue':''}">${device.name}</a>
		</c:forEach>
	</div>
	<div class="listTable">
		<table class="table-gray">
			<tr class="thead-gray">
				<td style="height: 28px; width: 35%;">名称</td>
				<td style="width: 35%;">值</td>
				<td style="width: 30%;">操作</td>
			</tr>
			<c:forEach items="${currentDevice.children}" var="property"
				varStatus="vss">
				<form action="#" name="editPropertyForm" method="post">
				<tr class="${sipConf.toggle?'tr-white':'tr-gray'}">
					<input type="hidden" name="deviceName"
						value="${currentDevice.name }" />
					<input type="hidden" name="index" value="${vss.count-1 }" />
					<input type="hidden" name="propertyName" value="${property.name }" />
					<td>${property.name }</td>
					<td>${property.valueEditor }</td>
					<td><input type="button" value="删除"
						onclick="remove(${vss.count-1})" /></td>
				</tr>
				</form>
			</c:forEach>
			<c:if test="${!empty currentDevice&&currentDevice.canInsertProperty}">
				<tr class="${sipConf.toggle?'tr-white':'tr-gray'}">
					<td><select name="insertNameSelect" id="insertNameSelect">
							<c:forEach items="${currentDevice.canSelectProperties}"
								var="propertyValue" varStatus="vss">
								<option value="${propertyValue }">${propertyValue }</option>
							</c:forEach>
					</select></td>
					<td></td>
					<td><input type="button" value="插入" onclick="insert(-1)" /></td>
				</tr>
			</c:if>
		</table>
	</div>
</body>
</html>
<!-- 

 -->